package com.leiyuan.content.controller;

import com.leiyuan.content.service.TeachplanService;
import com.leiyuan.dto.BindTeachplanMediaDto;
import com.leiyuan.dto.SaveTeachplanDto;
import com.leiyuan.dto.TeachplanDto;
import com.leiyuan.po.Teachplan;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author leiyuan
 * @version 1.0
 * @description TODO
 * @date 2023/4/18 18:22
 */
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
@RestController
public class TeachplanController {

    @Autowired
    TeachplanService teachplanService;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId",name = "课程基础Id值",required = true,dataType = "Long",paramType = "path")
    @GetMapping("teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        return teachplanService.findTeachplanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan( @RequestBody SaveTeachplanDto teachplan){
        teachplanService.saveTeachplan(teachplan);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "课程计划和媒资信息解除绑定")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    void untieMedia( @PathVariable Long teachPlanId, @PathVariable String mediaId){
        teachplanService.untieMedia(teachPlanId,mediaId);
    }

    @ApiOperation(value = "查询课程计划信息")
    @GetMapping("/teachplan/{teachplanId}")
    public Teachplan getTeachplanInfo(@PathVariable("teachplanId") Long teachplanId){
        return teachplanService.findTeachplanInfo(teachplanId);
    }
}
